package com.joey.supermarket.service;

import com.joey.supermarket.model.Customer;
import com.joey.supermarket.model.Fruits;
import com.sun.org.apache.xpath.internal.operations.Mod;

/**
 * @author 智刚
 * @data : 2021/8/7 16:07
 * @des ：超市服务
 */
public class SuperMarketService {

    /**
     *
     * @param customer 顾客和他的购物车
     * @return
     */
    public double fruitPrice(Customer customer){
        double price = 0;
        for (Fruits fruits:customer.getShopCar()){
            price += fruits.getUnitPrice() * fruits.getWeight();
            System.out.println(fruits.getFruitName() + fruits.getUnitPrice() * fruits.getWeight());
        }
        return price;
    }

    /**
     *
     * @param discount  折扣
     * @param fruits    水果种类
     * @return  折后总价
     */
    public double discountPrice(double discount, Fruits fruits){
        return discount * fruits.getUnitPrice() * fruits.getWeight() / 10;
    }

    public double fruitPriceTwo(Customer customer) {
        double price = fruitPrice(customer);
        Double reduction = price/100;
        price = price - reduction.intValue()*10;
        return price;
    }

    public double fruitPriceThree(Customer customer) {
        double price = fruitPrice(customer);
        boolean b = price - 100 >= 0;
        if (b){
            b = price - 300 >= 0;
            if (b){
                price = price - 50;
            }else {
                price = price - 10;
            }
        }
        return price;
    }
}
